<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div ui-layout-center">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="user-form">
                <input type="hidden" id="deptId" name="deptId">
                <input type="hidden" id="parentId" name="parentId">
                <div class="select-list">
                    <ul>
                        <li>
                            用户名称：<input type="text" name="nickName"/>
                        </li>
                        <li>
                            真实姓名：<input type="text" name="realName"/>
                        </li>
                        <li>
                            手机号：<input type="text" name="phone"/>
                        </li>

                        <li>
                            状态：
                            <select name="delFlag" th:with="type=${@dict.getType('del_flag')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <li>
                            用户类型：
                            <select name="userType" th:with="type=${@dict.getType('user_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>


                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="module:user:add">
                <i class="fa fa-plus"></i> 添加
            </a>

            <a class="btn btn-success btn-edit disabled" onclick="recover()"
               shiro:hasPermission="module:user:recover">
                <i class="fa fa-check-square-o"></i> 启用
            </a>

            <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="module:user:remove">
                <i class="fa fa-remove"></i> 禁用
            </a>

            <a class="btn btn-primary" onclick="userDetailMoney()" shiro:hasPermission="module:userDetailMoney:detailList">
                <i class="fa fa-plus"></i> 用户金额流水
            </a>

            <a class="btn btn-primary btn-edit disabled" id="chongzhi" onclick="addMoney()" shiro:hasPermission="module:user:add">
                <i class="fa fa-plus"></i> 充值
            </a>

            <a class="btn btn-primary" onclick="reduceMoney()" shiro:hasPermission="module:money:reduce">
                <i class="fa fa-minus"></i> 扣除
            </a>

            <a class="btn btn-primary btn-edit disabled" onclick="resetPayPwd()" shiro:hasPermission="module:wallet:resetPayPwd">
                <i class="fa fa-plus"></i> 重置支付密码
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('module:user:edit')}]];
    var redCountFlag = [[${@permission.hasPermi('module:user:redCount')}]];
    var removeFlag = [[${@permission.hasPermi('module:user:remove')}]];
    var recoverFlag = [[${@permission.hasPermi('module:user:recover')}]];
    var prefix = ctx + "module/user";
    var userType = [[${@dict.getType('user_type')}]];
    var leiType = [[${@dict.getType('lei_type')}]];
    var delFlag = [[${@dict.getType('del_flag')}]];
    var robotType = [[${@dict.getType('robot_type')}]];
    var roomBoss = [[${@dict.getType('roomBoss')}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            modalName: "用户",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'nickName',
                    title: '昵称'
                },
                {
                    field: 'delFlag',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(delFlag, value);
                    }
                },
                {
                    field: 'money',
                    title: '余额'
                },
                {
                    field: 'freezeMoney',
                    title: '冻结余额'
                },
                {
                    field: 'phone',
                    title: '手机号'
                },

                {
                    field: 'realName',
                    title: '真实姓名'
                },
                {
                    field: 'leiPercent',
                    title: '单雷概率'
                },
                {
                    field: 'oneLeiPercent',
                    title: '多雷1雷概率'
                },
                {
                    field: 'twoLeiPercent',
                    title: '多雷2雷概率'
                },
                {
                    field: 'threeLeiPercent',
                    title: '多雷3雷概率'
                },
                {
                    field: 'userType',
                    title: '用户类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(userType, value);
                    }
                },
                {
                    field: 'roomBoss',
                    title: '房间职位',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(roomBoss, value);
                    }
                },
                {
                    field: 'robotType',
                    title: '机器人类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(robotType, value);
                    }

                },
                {
                    field: 'leiType',
                    title: '机器人受罚类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(leiType, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + redCountFlag + '" href="#" onclick="redCount(\'' + row.id + '\')"><i class="fa fa-search"></i>红包记录</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>禁用</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    //启用
    function recover() {
        var url = prefix + '/recover';
        var id = "";

        if ($.common.isNotEmpty(id)) {
        } else {
            id = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (id.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
        }
        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: {id: id[0]},
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.alertSuccess(result.msg);
                    $.table.refresh();
                } else {
                    $.modal.alertError(result.msg);
                }
            }
        };
        $.ajax(config);
    }

    //禁用
    function forbid() {
        var url = prefix + '/remove';
        var id = "";

        if ($.common.isNotEmpty(id)) {
        } else {
            id = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (id.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
        }

        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: {id: id[0]},
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.alertSuccess(result.msg);
                    $.table.refresh();
                } else {
                    $.modal.alertError(result.msg);
                }
            }
        };
        $.ajax(config);
    }

    //用户金额流水
    function userDetailMoney() {
        var id = "";

        if ($.common.isNotEmpty(id)) {
        } else {
            id = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (id.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
        }


        var url = prefix + '/detailList/' + id;
        createMenuItem(url, "用户金额流水");
    }

    //检查用户
    function check(id) {
        var url = prefix + '/checkUser';
        var data = {};
        data.id = id;

        var flag = false;

        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: data,
            async: false,
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    flag = true;
                } else {
                    $.modal.alertError(result.msg);
                    flag = false;
                }
            }
        };
        $.ajax(config);
        return flag;
    }

    //充值
    function addMoney() {
        var id = "";
        if ($.common.isNotEmpty(id)) {
        } else {
            id = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (id.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
        }

        //检查用户
        var flag = check(id[0], 1);

        if (!flag) {
            return;
        }

        var url = prefix + '/toAddMoney?id=' + id;
        $.modal.open("充值", url);
    }

    function reduceMoney() {
        var id = "";
        if ($.common.isNotEmpty(id)) {
        } else {
            id = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (id.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
        }
        //检查用户
        var flag = check(id[0], 1);

        if (!flag) {
            return;
        }

        var url = prefix + '/toReduceMoney?id=' + id;
        $.modal.open("扣除", url);
    }

    /* 红包统计 */
    function redCount(id,width,height) {
        var url = prefix+"/redCount/{id}";
        var _url = $.common.isEmpty(id) ? url : url.replace("{id}", id);
        var _width = $.common.isEmpty(width) ? "800" : width;
        var _height = $.common.isEmpty(height) ? ($(window).height() - 50) : height;
        //如果是移动端，就使用自适应大小弹窗
        if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)) {
            _width = 'auto';
            _height = 'auto';
        }
        layer.open({
            type: 2,
            area: [_width + 'px', _height + 'px'],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "红包记录统计",
            content: _url,
            btn: '关闭',
            // 弹层外区域关闭
            shadeClose: true,
            success: function(layer) {
                layer[0].childNodes[3].childNodes[0].attributes[0].value='layui-layer-btn1';
            },
            btn1: function(index) {
                layer.close(index);
            }
        });
    }

    // 重置支付密码
    function resetPayPwd() {
        var id = "";
        if ($.common.isNotEmpty(id)) {
        } else {
            id = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.uniqueId);
            if (id.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
        }
        var url = prefix + '/resetPayPwd';
        var data = {};
        data.userId = id[0];

        var flag = false;

        var config = {
            url: url,
            type: "post",
            dataType: "json",
            data: data,
            async: false,
            success: function (result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.alertSuccess(result.msg);
                } else {
                    $.modal.alertError(result.msg);
                }
            }
        };
        $.ajax(config);
        return flag;
    }


</script>
</body>
</html>